#include "CellWidget.hpp"
#include "StyleManager.hpp"
#include "View.hpp"
#include "ChessGame.hpp"
#include "LinkManager.hpp"

#define CELL_HEIGHT	30
#define CELL_WIDTH 	30
#define CELL_XOFFSET	0
#define CELL_YOFFSET	0

CellWidget::CellWidget(Cell* cell)
	: StaticSpriteWidget(new StaticSprite(StyleManager::getInstance()->getStyle()->getCellPixmap(cell->getColor(), Style::C_STANDARD), 
										  ChessGame::getInstance()->getView()->getScene(), 
										  0.92
										  )
					     ), cell(cell), connected(false)
{		
	this->setPos(CELL_XOFFSET + cell->getPosition().getRealX() * CELL_HEIGHT, 
				 CELL_YOFFSET + 210 - (cell->getPosition().getRealY() * CELL_WIDTH));
}

CellWidget::~CellWidget()
{}

void CellWidget::setActivatedAsChoice(bool val)
{
	if (val)
	{
		this->spr->setPixmap(StyleManager::getInstance()->getStyle()->getCellPixmap(cell->getColor(), Style::C_CHOICE));
		if (!connected)
		{
			connect (this, SIGNAL(clicked()), LinkManager::getInstance(), SLOT(cellChoice()));
			connected = true;
		}
	}
	else
	{	
		this->spr->setPixmap(StyleManager::getInstance()->getStyle()->getCellPixmap(cell->getColor(), Style::C_STANDARD));
		if (connected)
		{
			disconnect(this, SIGNAL(clicked()), 0, 0);
			connected = false;
		}
	}
}

Cell* CellWidget::getCell() const
{	return cell;	}



